package com.exam.action;


import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;

/**
 * 
 * <p>Title: LogoutAction</p>
 * <p>Description:用户登出 </p>
 * <p>Company: CHNI</p> 
 * @author 陈维康
 * @date 2017年4月19日
 */
public class LogoutAction implements SessionAware{

	private Map<String, Object> application;  
	
	public String adminLogout(){
		this.session.remove("admin");
		return "success";
	}
	
	/**
	 * 考生退出考试
	 * 1.在线人数减少
	 * 2.清空 session
	 * @return
	 */
	public  String examLogout(){
		this.session.remove("student");
		application = ActionContext.getContext().getApplication();
		if(application.get("countStudent")!=null){
			 int m = (Integer) application.get("countStudent")-1;
			 if(m<0) m=0;
			 application.put("countStudent", m);
		 }else{
			 application.put("countStudent", 0);
		 }
		return "success";
	}
	
	Map<String, Object> session;
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
}
